13
https://raw.githubusercontent.com/CoboVault/cobo-vault-cold/master/coinlib/src/test/java/com/cobo/coinlib/Base43Test.java
/*
 * Copyright (c) 2020 Cobo
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * in the file COPYING.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.cobo.coinlib;

import com.cobo.coinlib.utils.Base43;

import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class Base43Test {

    String electrum43TransactionString = "71OUKK$VH33.J1Y/K8Q8T3-F8X59N/YIO*LXY.7320F/5.KN$EG47LC*I1VP$S7FS2+.KAJR5:8$-MDQTMHA54/QT3R$JVX/WRDLONP/*TJLGIHRB.KNSGZWVUW9TOSOE6G1::..-NLQNJD-R1GNJ.HA7A1M.6CS:-60X9LR9XHHB6B1KLTX4T/EZN3$ZWW+J10-Z9QU-N9HHU$EV865ED$3JD$ZUJ6IA2Z:.WXKXTCK2:BMZFW3F+QI.GS54BN3*Q1T*3C1ESF0QA:ZOX1RLG/I/I1GPL:FPLRKAKH:KO4*U0YAK16-CGI-Z7A3EQAJ8Q484VA05FE7JO$-U.HBFWNFSFD8EGPJR*QV3YJD5SHA3BLWM+FR0*FS7M89S115/PU7:6-XW:EPL4/+7N2RFM/**Z6J*/--97OD2QWSLUE7G5F42ATP0SAV52U1GV+WZAJX$T0R:49QIDYJUKOXWX.$UUTR5596EOVK88E$ALJ-/MEML4883J5572D1-LRSXTRYL:X39U8QQ0XII09I5M3:13$U+B7V3S1+YUQM3:G+A/IH9+$.CHEOGE-3NX:OZ+H1D*N3IFC9+/ZT*S/O45QLRC";
    String hexTransactionString = "0100000001ac01d39c405d31d3d20b00254e84dce9838b9c280f3aa07bf77a1510d8f8779900000000fd4201004830450221009a4065d3b869f20b6e858e0722d9b511213e09dcf1b61072cccbff340c7f424e022034c42927a64fe323d8e8b76d99960322bf0664fdad9994939aedac74a32ca8c701483045022100dda3d5974ae1c06d9742c7aa5e2f789218054c60476f049300c7d4d0395819aa02201f484d7a2b4cc6186b23f54ea4099a728760d71fcc0c7a82bd056c6eaeacf3ab014cad5221020de4d18c5b852a3c1d1f1033a812b019c396b75cab2a248089b09632c7bbdda221024ee8ab3639ea02d7fac7e90078b16c06811573d7046cd06b5d1d8d7e50e0767a21025392159aaf967c2f7e1dca92b68d1b3abaf44a9d3903f7382e76f9f64e7bfa242102df269b98c7ea5bdec1aac268d6107b827163d3a0ca8bd3522279d14c46e1bf1a2103cfbf85d74dddf892b3b6f918fd36dab13cc904d9ba3c9306e9e25fe53ebde08155aeffffffff01131f0000000000001976a914e9cc1b59c97f860f5c629c23d93920da60648d0388ac00000000";
    String electrum43RencodedString = "7TG5RUO-Y-9:G5IU$61+B0MOM7Q698PSE/V6JYQTVD2GF5GB$B*-A*11AJ8J8M46QNXW/16ZBRFLK9N1KIIVROQI39KVI4Y*7:XJK+L/+U67O*B0:7WGIA0C424KG*9A2LZN+IGS2.OWM4J.VW-*TR$TR7/QBG$W*U4ABSMT-S$XX/.TESGFAZID775.J/WTGZZ4-4GZ3HTN26MEPA9EO$X*/0W3PHT5G*8B7$05J5NZMH-CGGX4O.I*-T+$2$*3081Y.+M+K+NM*64$Q.29VKQ9Q*GCXTTDH-UW1TF4H.1NPGZX:JLGU9S752WFLD1YR7Y3TNTR695G8WO1/3VX6-AN8/EMJ0-J25L/S3X8-1IV7FZA:554W1Q5HSH/ZR0EQPHN1NNHBQ:NDEF5R5247NU7M9P-4D-W3FLIAZ9OQLOS0SDN3B:E9VR$U25E/8VW:4HDJAL***W/HI16/4Z0G-SOKEC++90*HV24ZO/MDXPU-44YCSLF71:01SERXU$AKDH*1NS1/M8GNSS$5R+E+6+0.15AUPU8MXHAS16Q7WH9896SW2+HGA5I0C$:/RA1ZRK:XL-ECGHBO$X9OYK7.PD2FTP+Q711C5H*OBDMQWD.YFCHWD6I32IPH2J6OPB33288I/*.MZG$DEXF2V5A3I9ZC.W6:*NOLNC3PNK+B$1W*4ZAS79$R*JFGM5X$+IHOP68U7E+6KPVPV6OGC0/UHQW3NXR7*2QJO1T83DM7C9N77D:4/QMDYL:9H.L3QAI04INCVVVK4YHNB9QO8X1:7ANE5$2V6OI575WO5/Y-OLHJ3/.+XU1U-K3RQH:4M1X5WJF40CR3VI*QXD5L*8JDA-UIV/-4.I*7ENPT$$*3-7A./.+8WEKWI7Z/S5*.LCUUJCT1.7JS/Z1YQN3FSZMG0BW-MUWCU2FGT2O2KZ3/QOA952-1MU0.F-F../TCHTV4AU*/GI8N-5TFC73U27-/T0P432--4QP4IAVP8./V7HKJHJKCY/KXPV-$8/W7+8SH++VW8M8S3NYNK-29812R60$QQ/:$V+L1Q/3X7MBV4BQCHX1FR0WOFAKF+DW37VKTJO6P7SJ+GBLQ5QSNBLKL$8*5S.D1G//BMPVE0V1-6QCFA/AK1H.X7O85H7U56QGV.I*M9-I.1G:KP/N0A6ARQQSVT/46GGSXXG.M*T5UD3RCG:EZNV+*3";
    String badString = "invalid characters";
    @Test
    public void test() {
        assertEquals(Hex.toHexString(Base43.decode(electrum43TransactionString)), hexTransactionString);
        assertEquals(Base43.encode(Hex.decode(hexTransactionString)), electrum43TransactionString);

        String s = "I-5VP47::E$M+XWAA*1VA:/+XS18RM8/VWBACYP48+4VE6W$J:$4*THZ42ZA2582N:.5H$9$.QH7--1EJR-B5JIH-NPH58ACH/-852GAU0LJ$FW..:B0IFLIQY$TLE60$B8L7/NYFZ-EQ230FN6WLD/7*ZQ57B60826PNQ62NIAW+4OQ7ZZ4KOJVRBD73+31HK2FNA6HVT220NI3OVW56J/WI9.5+IMAIJY*-ZCF5SPPGL82S7-9Q2KI:*NQ:D$5E.CGY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